package basic.study.leetcode;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @ClassName Mid146
 * @Description
 * @Company inspur
 * @Author Kevin
 * @Date 2020/6/30 10:21
 * @Version 1.0
 */
public class Mid146 {
    class LRUCache {
        LinkedHashMap<Integer, Integer> map;

        public LRUCache(int capacity) {
            map = new LinkedHashMap<Integer, Integer>((int)(capacity / 0.75f), 0.75f, true){
                @Override
                protected boolean removeEldestEntry(Map.Entry<Integer, Integer> eldest) {
                    return size() > capacity;
                }
            };
        }

        public int get(int key) {
            return map.getOrDefault(key, -1);
        }

        public void put(int key, int value) {
            map.put(key, value);
        }
    }

}
